package es.cea.Listener;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import es.cea.agendatelefonica.ContactoTel;



/**
 * Application Lifecycle Listener implementation class IniciarContactos
 *
 */
@WebListener
public class IniciarContactos implements ServletContextListener {

 
    public IniciarContactos() {

    }

	
    public void contextInitialized(ServletContextEvent arg0) {
    
    	ServletContext servletContext = arg0.getServletContext();
		
		Object source = arg0.getSource();
		
		ArrayList<ContactoTel> contactos = creaContactos();
		
		servletContext.setAttribute("contactos", contactos);
    }

    public ArrayList<ContactoTel> creaContactos() {
    	List<ContactoTel> contactos=new ArrayList<ContactoTel>();
		contactos.add(new ContactoTel("Dario", "123456"));
		contactos.add(new ContactoTel("Maria", "7891011"));
		contactos.add(new ContactoTel("Joselito", "12131415"));
		
		return (ArrayList<ContactoTel>) contactos;
		
    }
    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
    }
	
}
